﻿/*
 * fbasync - An Asynchronous Facebook API for .NET
 * Copyright (C) 2007 ittybittysoft
 * Email: info@ittybittysoft.com
 * Portions of the library are based on the Facebook Developer Toolkit
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
using System;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.Serialization;
using System.Xml;
using System.Collections.Generic;

namespace fbasync
{
    [DataContract(), Serializable()]
    public class Album
        : FacebookEntity
    {
        public readonly static IEnumerable<string> AllFields =
            new string[] { "aid", "owner", "name", "size", "cover_pid", "created", "modified", "location", "link", "description" };

        public const string DefaultOrderBy = "name";
        public const string FacebookEntity = "album";

        [DataMember()]
        public string aid { get; set; }

        [DataMember()]
        public long? owner { get; set; }

        [DataMember()]
        public string name { get; set; }

        [DataMember()]
        public int? size { get; set; }

        [DataMember()]
        public string cover_pid { get; set; }

        [DataMember()]
        public DateTime? created { get; set; }

        [DataMember()]
        public DateTime? modified { get; set; }

        [DataMember()]
        public string location { get; set; }

        [DataMember()]
        public string link { get; set; }

        [DataMember()]
        public string description { get; set; }

        public static IList<Album> FromFqlResult(XmlDocument fqlResult, bool keepXml)
        {
            List<Album> results = fqlResult.GetFqlResults(keepXml, e =>
                new Album
                {
                    aid = e.GetChildText("aid"),
                    cover_pid = e.GetChildText("cover_pid"),
                    owner = e.GetChildLong("owner"),
                    name = e.GetChildText("name"),
                    description = e.GetChildText("description"),
                    location = e.GetChildText("location"),
                    link = e.GetChildText("link"),
                    size = e.GetChildInt("size"),
                    created = e.GetChildUnixTime("created"),
                    modified = e.GetChildUnixTime("modified")
                });

            return results;
        }
    }
}